package day_2022_9_to_12.Day;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2022/09/06 10:29
 **/
public class Day4_3_Num1_TwoSum {
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            Map<Integer, Integer> map = new HashMap<>();
            for(int i = 0; i < nums.length; ++i){
                if(map.containsKey(nums[i])){
                    return new int[]{map.get(nums[i]), i};
                }
                map.put(target-nums[i], i);
            }
            return new int[0];
        }
    }
}